/**
 * 
 */
package cn.x.kindergarten.dao.impl;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import cn.x.kindergarten.dao.BaseDao;

/**
 * @author Xu Hang @ 2014年12月11日 下午4:37:44
 *
 */
public class BaseDaoImpl<T> implements BaseDao<T> {
	@Autowired
    public SqlSession sqlSession;
	public String path = null;
	public Class type;
    public BaseDaoImpl(){
        this.type = this.getDAOClass();
        this.path = "cn.x.kindergarten.mapper." + type.getName().substring(type.getName().lastIndexOf(".")+1) +".";
    }
    private Class getDAOClass(){
        Class clazz = (Class)((ParameterizedType) this.getClass().getGenericSuperclass())
           .getActualTypeArguments()[0];
        return clazz;
   }
	public T query(Serializable id) {
		return sqlSession.selectOne(this.path+"query", id);
	}
	public void insert(T t) {
		sqlSession.insert(this.path+"insert", t);
		
	}
	public void delete(Serializable id) {
		sqlSession.delete(this.path+"delete", id);
	}
	public void update(T t) {
		sqlSession.update(this.path+"update", t);
	}
	public List<T> queryAll() {
		return sqlSession.selectList(this.path+"queryAll");
	}

}
